﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using EpsiRisk.MoteurJeu;
using EpsiRisk.Plateaux;

namespace EpsiRisk.AffichageJeu
{
    public class ClassZonePopupMenu : ClassZone
    {
        public bool Visible;
        static Texture2D SpritePopupMenu;
        static Texture2D SpriteNouveauJeu;
        static Texture2D SpriteOption;
        static Texture2D Spritefermer;
        static Texture2D soundOn;
        static Texture2D soundOff;
        static Texture2D SpriteSauvegarder;
        static Texture2D SpriteCharger;

        ClassBouton nouveaujeu;
        ClassBouton option;
        ClassBouton son;
        ClassBouton fermerpopup;
        ClassBouton sauvegarder;
        ClassBouton charger;

        public ClassZonePopupMenu()
        {
            position = new Vector2(300, 100);
            height = 333;
            width = 200;
            backcolor = Color.TransparentWhite;
            Visible = false;
        }

        internal override void Draw(SpriteBatch spriteBatch)
        {
            if (Visible)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(SpritePopupMenu, position, null, Color.White);
                spriteBatch.End();
                base.Draw(spriteBatch);
            }
        }

        internal override void initialiser(ContentManager content)
        {
            SpriteCharger = content.Load<Texture2D>("Sprites/PopupMenu/SpriteCharger");
            SpriteSauvegarder = content.Load<Texture2D>("Sprites/PopupMenu/SpriteSauvegarder");
            SpritePopupMenu = content.Load<Texture2D>("Sprites/PopupMenu/SpritePopupMenu");
            SpriteNouveauJeu = content.Load<Texture2D>("Sprites/PopupMenu/SpriteNouveauJeu");
            SpriteOption = content.Load<Texture2D>("Sprites/PopupMenu/SpriteOption");
            Spritefermer = content.Load<Texture2D>("Sprites/PopupMenu/Spritefermer");
            soundOn = content.Load<Texture2D>("Sprites/PopupMenu/sound");
            soundOff = content.Load<Texture2D>("Sprites/PopupMenu/sound_muted");
            //sound = soundOn;
            //bouton nouveaujeu
            nouveaujeu = new ClassBouton(SpriteNouveauJeu);
            nouveaujeu.position = new Vector2(23, 25);
            nouveaujeu.height = 22;
            nouveaujeu.width = 153;
            AddBouton(nouveaujeu);
            nouveaujeu.Clicked += new EventHandler(nouveaujeu_Clicked);
            //bouton option
            option = new ClassBouton(SpriteOption);
            option.position = new Vector2(23, 55);
            option.height = 22;
            option.width = 153;
            AddBouton(option);
            option.Clicked += new EventHandler(option_Clicked);
            //bouton son
            son = new ClassBouton(soundOff, soundOn);
            son.position = new Vector2(23, 280);
            son.width = 30;
            son.height = 30;
            AddBouton(son);
            son.Clicked += new EventHandler(son_Clicked);
            //bouton fermer le popupMenu
            fermerpopup = new ClassBouton(Spritefermer);
            fermerpopup.position = new Vector2(186, 2);
            fermerpopup.width = 13;
            fermerpopup.height = 15;
            AddBouton(fermerpopup);
            fermerpopup.Clicked += new EventHandler(fermerpopup_Clicked);
            //bouton charger 148 22
            charger = new ClassBouton(SpriteCharger);
            charger.width = 148;
            charger.height = 22;
            charger.position = new Vector2(23,115);
            AddBouton(charger);
            charger.Clicked += new EventHandler(charger_Clicked);
            //bouton sauvegarder 184 22
            sauvegarder = new ClassBouton(SpriteSauvegarder);
            sauvegarder.width = 150;
            sauvegarder.height = 22;
            sauvegarder.position = new Vector2(23, 85);
            AddBouton(sauvegarder);
            sauvegarder.Clicked += new EventHandler(sauvegarder_Clicked);
        }

        void charger_Clicked(object sender, EventArgs e)
        {
            Console.WriteLine("Clic sur le bouton charger");
            Visible = false;
            ClassGestionSauvegardes.chargerPartie();
        }

        void sauvegarder_Clicked(object sender, EventArgs e)
        {
            Console.WriteLine("Clic sur le bouton sauvegarder");
            Visible = false;
            ClassGestionSauvegardes.sauvegarderPartie();
        }

        void son_Clicked(object sender, EventArgs e)
        {
            Console.WriteLine("Clic sur le bouton son");
            if (ClassSon.BackMusicVolume == 0)
            {
                son.active = true;
                ClassSon.BackMusicVolume = 100;
            }
            else
            {
                son.active = false;
                ClassSon.BackMusicVolume = 0;
            }
        }

        void option_Clicked(object sender, EventArgs e)
        {
            Console.WriteLine("Clic sur passer le bouton option");
        }

        void nouveaujeu_Clicked(object sender, EventArgs e)
        {
            Console.WriteLine("Clic sur passer le bouton nouveaujeu");
            Visible = false;
            
            ClassDonneesGlobales.zoneNouveauJeu.Visible = true;
            ClassDonneesGlobales.zonePopupMenu.Visible = false;
            ClassDonneesGlobales.zoneNouveauJeu.DessinerJoueurs();
        }

        void fermerpopup_Clicked(object sender, EventArgs e)
        {
            Console.WriteLine("Clic sur passer fermer le menu PopUp");
            Visible = false;
        }
    }
}
